<?php

/**
 * @todo search for payments by current status
 * @todo search for payments by date
 */
class Am_Query_Job extends Am_Query_Renderable {
   // protected $template = 'member/usercp/_job-search.phtml';
    function  __construct() {
        parent::__construct(Am_Di::getInstance()->jobTable, 'j');
    }
    function initPossibleConditions(){
      
    }

}


class Am_Query_Job_Condition_Filter
extends Am_Query_Condition
implements Am_Query_Renderable_Condition
{
    protected $title = "Quick Filter";
    protected $filter;
	protected $isUser;
    public function getId() {
        return 'filter';
    }
	public function setUser($isUser){
		$this->isUser = $isUser;
	}
    public function isEmpty() {
        return $this->filter === null;
    }
    public function renderElement(HTML_QuickForm2_Container $form) {
       $form->options['Quick Filter'][$this->getId()] = $this->title;
       $group = $form->addGroup($this->getId())
           ->setLabel($this->title)
           ->setAttribute('id', $this->getId())
           ->setAttribute('class', 'searchField empty');
        $group->addText('val');
    }
    public function setFromRequest(array $input) {
        if (is_string($input)) {
            $this->filter = $input;
            return true;
        } elseif (@$input['filter']['val']!='') {
            $this->filter = $input['filter']['val'];
            return true;
        }
    }
    public function _getWhere(Am_Query $q){
        $a = $q->getAlias();
        $f = '%'.$this->filter.'%';
		//if($this->isUser)
       // return $q->escapeWithPlaceholders("($a.url LIKE ?)",
       //         $f);
		//else
		return $q->escapeWithPlaceholders("($a.url LIKE ?)",
                $f);
    ;}
    public function getDescription(){
        $f = htmlentities($this->filter);
        return "url contains string [$f]";
    }
}
